home *** CD-ROM | disk | FTP | other *** search
- unit ntc_ciel_client_observer;
- {
- Copyright (C) 2004 - 2006 Andrew Sprott
-
- http://astronomy.crysania.co.uk
- astro@trefach.co.uk
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- }
-
- interface
-
- uses
- Windows,
- Messages,
- SysUtils,
- Variants,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- StdCtrls,
- ExtCtrls,
- inifiles,
- ComCtrls,
-
- ntc_ciel_client_form;
-
- const
- max_latitude_degrees=90;
- max_longitude_degrees=360;
-
- type
- Tscope_observer = class(tform)
- observer_panel: TPanel;
- observatory_group: TGroupBox;
- latitude_label: TLabel;
- longitude_label: TLabel;
- time_zone_label: TLabel;
- time_zone_edit: TEdit;
- longitude_degrees_edit: TEdit;
- longitude_degrees_up_down: TUpDown;
- longitude_minutes_edit: TEdit;
- longitude_minutes_up_down: TUpDown;
- longitude_seconds_edit: TEdit;
- longitude_seconds_up_down: TUpDown;
- move_degrees_label: TLabel;
- move_minutes_label: TLabel;
- move_seconds_label: TLabel;
- latitude_degrees_edit: TEdit;
- latitude_degrees_up_down: TUpDown;
- latitude_minutes_edit: TEdit;
- latitude_minutes_up_down: TUpDown;
- latitude_seconds_edit: TEdit;
- latitude_seconds_up_down: TUpDown;
- time_zone_up_down: TUpDown;
- hours_label: TLabel;
-
- { form handling }
- procedure formcreate(
- Sender:TObject);
-
- { configuration }
- procedure load_settings;
-
- procedure save_settings;
-
- { events }
- procedure latitude_edit_boxes;
- procedure longitude_edit_boxes;
-
- procedure latitude_degrees_editKeyPress(
- Sender: TObject;
- var Key: Char);
-
- procedure latitude_minutes_editKeyPress(
- Sender: TObject;
- var Key: Char);
-
- procedure latitude_seconds_editKeyPress(
- Sender: TObject;
- var Key: Char);
-
- procedure latitude_degrees_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
-
- procedure latitude_minutes_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
-
- procedure latitude_seconds_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
-
- procedure longitude_degrees_editKeyPress(
- Sender: TObject;
- var Key: Char);
-
- procedure longitude_minutes_editKeyPress(
- Sender: TObject;
- var Key: Char);
-
- procedure longitude_seconds_editKeyPress(
- Sender: TObject;
- var Key: Char);
-
- procedure longitude_degrees_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
-
- procedure longitude_minutes_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
-
- procedure longitude_seconds_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
-
- procedure time_zone_editChange(
- Sender: TObject);
-
- procedure FormShow(
- Sender: TObject);
-
- procedure adjust;
-
- procedure check_activate(
- Sender: TObject);
-
- procedure form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
-
- procedure time_zone_up_downClick(
- Sender: TObject;
- Button: TUDBtnType);
-
- private
- { Private declarations }
- latitude_degrees_updating,
- latitude_minutes_updating,
- latitude_seconds_updating,
- longitude_degrees_updating,
- longitude_minutes_updating,
- longitude_seconds_updating,
- time_zone_updating:boolean;
- public
- { Public declarations }
- { observer location }
- latitude,
- longitude:double;
- degrees_ra,
- degrees_dec,
- degrees_az,
- degrees_alt:double;
- time_zone:integer;
- date_time:tdatetime;
- { configuration }
- dimensions:dimensions_record;
- { location }
- latitude_degrees,
- latitude_minutes,
- latitude_seconds,
- longitude_degrees,
- longitude_minutes,
- longitude_seconds:extended;
-
- Function set_observer(
- lat,
- long,
- zone:double;
- date_time:Tdatetime)
- :boolean;
-
- { events }
- procedure check_visible_and_show_hide(
- sender:tobject);
-
- procedure hide_form;
- procedure show_form;
- end;
-
- var
- scope_observer: Tscope_observer;
-
- implementation
-
- uses
- ntc_ciel_client_control;
-
- {$R *.dfm}
-
- { -------------
- form handling
- ------------- }
-
- procedure tscope_observer.formcreate(
- Sender:TObject);
- begin
- time_zone:=strtointdef(time_zone_edit.text,0);
- latitude_degrees_updating:=false;
- latitude_minutes_updating:=false;
- latitude_seconds_updating:=false;
- longitude_degrees_updating:=false;
- longitude_minutes_updating:=false;
- longitude_seconds_updating:=false;
- time_zone_updating:=false;
- load_settings;
- case scope_type of
- lx200_type:observatory_group.visible:=true;
- autostar_type:observatory_group.visible:=true;
- end;
- visible:=false;
- end;
-
- Function tscope_observer.set_observer(
- lat,
- long,
- zone:double;
- date_time:Tdatetime)
- :boolean;
- begin
- result:=true;
- end;
-
- { -------------
- configuration
- ------------- }
-
- procedure tscope_observer.load_settings;
- begin
- ini_file:=tinifile.create(application_path+'ciel.ini');
- with ini_file do
- begin
- longitude:=readfloat('observer','longitude',4);
- latitude:=readfloat('observer','latitude',51);
- { form }
- scope.get_dimensions(scope_observer,@dimensions,'observer',ini_file);
- left:=dimensions.form_left;
- top:=dimensions.form_top;
- visible:=readbool('observer','visible',false);
- end;
- ini_file.free;
- end;
-
- procedure tscope_observer.save_settings;
- begin
- with ini_file,dimensions do
- begin
- writefloat('observer','longitude',longitude);
- writefloat('observer','latitude',latitude);
- { form }
- scope.find_vdu(scope_observer,@dimensions);
- scope.write_dimensions(@dimensions,left,top,'observer',ini_file);
- writebool('observer','visible',visible);
- end;
- end;
-
- { ---------
- utilities
- --------- }
-
- procedure tscope_observer.latitude_edit_boxes;
- begin
- latitude_degrees:=strtofloatdef(latitude_degrees_edit.text,latitude_degrees);
- latitude_minutes:=strtofloatdef(latitude_minutes_edit.text,latitude_minutes);
- latitude_seconds:=strtofloatdef(latitude_seconds_edit.text,latitude_seconds);
- scope_control.normalise(
- max_latitude_degrees,latitude_degrees,latitude_minutes,latitude_seconds);
- latitude:=(latitude_seconds/60+latitude_minutes)/60+latitude_degrees;
- latitude_degrees_edit.text:=floattostr(latitude_degrees);
- latitude_minutes_edit.Text:=floattostr(latitude_minutes);
- latitude_seconds_edit.text:=floattostr(latitude_seconds);
- latitude_degrees_up_down.position:=trunc(latitude_degrees);
- latitude_minutes_up_down.position:=trunc(latitude_minutes);
- latitude_seconds_up_down.position:=trunc(latitude_seconds);
- end;
-
- procedure tscope_observer.longitude_edit_boxes;
- begin
- longitude_degrees:=strtofloatdef(longitude_degrees_edit.text,longitude_degrees);
- longitude_minutes:=strtofloatdef(longitude_minutes_edit.text,longitude_minutes);
- longitude_seconds:=strtofloatdef(longitude_seconds_edit.text,longitude_seconds);
- scope_control.normalise(
- max_longitude_degrees,longitude_degrees,longitude_minutes,longitude_seconds);
- longitude:=(longitude_seconds/60+longitude_minutes)/60+longitude_degrees;
- longitude_degrees_edit.text:=floattostr(longitude_degrees);
- longitude_minutes_edit.Text:=floattostr(longitude_minutes);
- longitude_seconds_edit.text:=floattostr(longitude_seconds);
- longitude_degrees_up_down.position:=trunc(longitude_degrees);
- longitude_minutes_up_down.position:=trunc(longitude_minutes);
- longitude_seconds_up_down.position:=trunc(longitude_seconds);
- end;
-
- { ------
- events
- ------ }
-
- procedure tscope_observer.latitude_degrees_editKeyPress(
- Sender: TObject;
- var Key: Char);
- begin
- if key=cr then
- latitude_edit_boxes;
- end;
-
- procedure tscope_observer.latitude_minutes_editKeyPress(
- Sender: TObject;
- var Key: Char);
- begin
- if key=cr then
- latitude_edit_boxes;
- end;
-
- procedure tscope_observer.latitude_seconds_editKeyPress(
- Sender: TObject;
- var Key: Char);
- begin
- if key=cr then
- latitude_edit_boxes;
- end;
-
- procedure tscope_observer.latitude_degrees_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
- begin
- if not latitude_degrees_updating then
- begin
- latitude_degrees_updating:=true;
- latitude_edit_boxes;
- latitude_degrees_updating:=false;
- end;
- end;
-
- procedure tscope_observer.latitude_minutes_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
- begin
- if not latitude_minutes_updating then
- begin
- latitude_minutes_updating:=true;
- latitude_edit_boxes;
- latitude_minutes_updating:=false;
- end;
- end;
-
- procedure tscope_observer.latitude_seconds_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
- begin
- if not latitude_seconds_updating then
- begin
- latitude_seconds_updating:=true;
- latitude_edit_boxes;
- latitude_seconds_updating:=false;
- end;
- end;
-
- procedure tscope_observer.longitude_degrees_editKeyPress(
- Sender: TObject;
- var Key: Char);
- begin
- if key=cr then
- longitude_edit_boxes;
- end;
-
- procedure tscope_observer.longitude_minutes_editKeyPress(
- Sender: TObject;
- var Key: Char);
- begin
- if key=cr then
- longitude_edit_boxes;
- end;
-
- procedure tscope_observer.longitude_seconds_editKeyPress(
- Sender: TObject;
- var Key: Char);
- begin
- if key=cr then
- longitude_edit_boxes;
- end;
-
- procedure tscope_observer.longitude_degrees_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
- begin
- if not longitude_degrees_updating then
- begin
- longitude_degrees_updating:=true;
- longitude_edit_boxes;
- longitude_degrees_updating:=false;
- end;
- end;
-
- procedure tscope_observer.longitude_minutes_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
- begin
- if not longitude_minutes_updating then
- begin
- longitude_minutes_updating:=true;
- longitude_edit_boxes;
- longitude_minutes_updating:=false;
- end;
- end;
-
- procedure tscope_observer.longitude_seconds_up_downChanging(
- Sender: TObject;
- var AllowChange: Boolean);
- begin
- if not longitude_seconds_updating then
- begin
- longitude_seconds_updating:=true;
- longitude_edit_boxes;
- longitude_seconds_updating:=false;
- end;
- end;
-
- procedure Tscope_observer.time_zone_editChange(
- Sender: TObject);
- begin
- time_zone:=strtointdef(time_zone_edit.text,0);
- end;
-
- procedure Tscope_observer.FormShow(
- Sender: TObject);
- begin
- with dimensions do
- begin
- top:=form_top;
- left:=form_left;
- end;
- end;
-
- procedure tscope_observer.adjust;
- begin
- with dimensions do
- begin
- form_top:=trunc(form_top/last_screen_height*current_height);
- form_left:=trunc(form_left/last_screen_width*current_width);
- end;
- if visible then
- show;
- end;
-
- procedure tscope_observer.check_visible_and_show_hide(
- sender:tobject);
- begin
- if visible then
- hide_form
- else
- show_form;
- scope.show_hide(sender,visible);
- end;
-
- procedure tscope_observer.hide_form;
- begin
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- Visible:=false;
- formstyle:=fsnormal;
- end;
-
- procedure tscope_observer.show_form;
- begin
- formstyle:=fsstayontop;
- Visible:=true;
- end;
-
- procedure Tscope_observer.check_activate(
- Sender: TObject);
- begin
- scope.form_activate(scope_observer,@dimensions);
- end;
-
- procedure Tscope_observer.form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
- begin
- visible:=false;
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- if ciel_closing then
- canclose:=true
- else
- canclose:=false;
- end;
-
- procedure Tscope_observer.time_zone_up_downClick(
- Sender: TObject;
- Button: TUDBtnType);
- begin
- if not time_zone_updating then
- begin
- time_zone_updating:=true;
- time_zone:=strtointdef(time_zone_edit.text,0);
- time_zone_updating:=false;
- end;
- end;
-
- end.
-